﻿using System;
using System.Text.RegularExpressions;

namespace Purdue.Helper
{
    public static class VersionHelper
    {
        public static bool IsBelowVista()
        {
            var versionVista = new Version(6, 0);
            return (Environment.OSVersion.Platform == PlatformID.Win32NT &&
                    Environment.OSVersion.Version < versionVista);
        }

        private const string VersionStringPattern = @"^\d+(\.\d+){0,3}$";

        public static bool TryParse(string value, out Version version)
        {
            var regex = new Regex(VersionStringPattern);
            var match = regex.Match(value);
            if (match.Success)
            {
                version = new Version(value);
                return true;
            }

            version = null;
            return false;
        }
    }
}
